﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MpSoft.Library.DAO.Customers;
using MpSoft.Library.DTO;
using MpSoft.Basic.Configuration;

namespace MpSoft.Library.BUSS.Customers
{
    #region  OrderProduct

    public class OrderProductBUSS
    {
        private const string ORDERPRODUCT_ALL_KEY = "Mp.orderproduct.all-{0}";
        private const string ORDERPRODUCT_BY_ID_KEY = "Mp.orderproduct.id-{0}";

        private static void OrderProductRemoveCache()
        {
            MpCache.RemoveByPattern(ORDERPRODUCT_ALL_KEY);
            MpCache.RemoveByPattern(ORDERPRODUCT_BY_ID_KEY);
        }

        public static int OrderProduct_Add(OrderProduct obj)
        {
            var result = OrderProductDAO.OrderProduct_Add(obj);
            return result;
        }

        public static void OrderProduct_AddProductToOrder(List<Cart> listCart, int OrderID)
        {
            foreach (var obj in listCart)
            {
                OrderProduct orderproduct = new OrderProduct();
                orderproduct.ProductID = obj.ProductID;
                orderproduct.OrderID = OrderID;
                orderproduct.Quantily = obj.Quantily;
                orderproduct.Total = obj.Total;
                OrderProduct_Add(orderproduct);
            }
        }

        public static int OrderProduct_Update(OrderProduct obj)
        {
            var result = OrderProductDAO.OrderProduct_Update(obj);
            return result;
        }

        public static int OrderProduct_Delete(int OPID)
        {
            var result = OrderProductDAO.OrderProduct_Delete(OPID);
            return result;
        }

        public static OrderProduct OrderProduct_ByID(int OPID)
        {
            var list = OrderProduct_Select(OPID, -1, -1);
            if (list != null)
                return list.FirstOrDefault();
            return null;
        }

        public static List<OrderProduct> OrderProduct_Select(int OPID, int ProductID, int OrderID)
        {
            return OrderProductDAO.OrderProduct_Select(OPID, ProductID, OrderID);
        }

    }

    #endregion
}
